
let content = $.cookie("searchContent");
let tag = $.cookie("searchTag");
jQuery(function () {
    jQuery.post("/demo/search", {"tagId":tag,"content":content,"userId":-1,"blogId":-1},function (rst) {
        var converter = new showdown.Converter(); //初始化转换器
        let trs = '';
        for (let i = 0; i < rst.length; i++) {
            let u = rst[i];
            var htmlcontent = converter.makeHtml(u.content); //将MarkDown转为html格式的内容
            let temp="/"+"${u.userId}"+"/"+"${u.blogId}";
            let time = u.createDate;
            let pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
            var createTime = time.replace(pattern, '$1/$2/$3');
            trs += `        <div class="first all">
            <div class="panel-body">
                <div class="index-title">
                    <div class="title text-center text">
                        <a href="/demo/blog/${u.blogId}" class="header-title text">${u.blogTitle}</a>
                    </div>
                    <hr style="margin: 0 0 10px 0;">
                </div>
                <div class="file-content hidden" style="max-height:250px">
                    ${htmlcontent}
                </div>
                <hr style="margin: 10px 0 0 0;">
                <div style="text-align: left">
                `;
            for(let j=0;j<u.blogTags.length;j++)
            {
                let a=u.blogTags[j];
                trs+=`
                   <span class="badge badge-pill badge-success">${a}</span>
                `;
            }
            trs+=`
                 </div>
                 <div style="text-align: right">
                    ${u.userInfo.userName}&nbsp;&nbsp;&nbsp;${createTime}
                 </div>
            </div>
        </div>
          `;
        }
        if (trs.length == 0) {
            trs = `
                <div  class="title text-center">没有数据</div>
                    `;
        }
        //把数据添加到tbody中
        jQuery("#add").html(trs);
    })
});

$(function () {
    $(window).scroll(function () {  //只要窗口滚动,就触发下面代码
        var scrollt = document.documentElement.scrollTop + document.body.scrollTop; //获取滚动后的高度
        if (scrollt > 10) {
            $("#back_top").fadeIn(400); //淡入
        } else {
            $("#back_top").stop().fadeOut(400); //如果返回或者没有超过,就淡出.必须加上stop()停止之前动画,否则会出现闪动
        }
    });
    $("#back_top").click(function () { //当点击标签的时候,使用animate在200毫秒的时间内,滚到顶部
        $("html,body").animate({scrollTop: "0px"}, 200);
    });
});